<?php

namespace app\admin\controller;

use think\Db;
class Friendship extends AdminController
{
    public function select()
    {

        
        $list = Db::name('friendship')->select();
       // dump($list);exit;
        return view('admin@friendship/index',['list'=>$list]);
    }

    public function add()
    {
        return view('admin@friendship/add');
    }

    public function doadd()
    {

//        dump(input('post.'));exit;
//        $p = $request->post();
        // $p = Request::instance()->post();
        // $p = input('post.');
//        var_dump($p);

//        dump(input('post.'));exit;
        $data = [
            'name' => input('post.name'),
            'status' => input('post.status'),
            'url' => input('post.url')

        ];

        $result = Db::name('friendship')->data($data)->insert();

        if ($result > 0) {
            return $this->success('添加成功', url('admin/friendship/select'));
        } else {
            return $this->error('添加失败');
        }


    }

    public function del($id)
    {
        //        dump($_GET);exit;
//        dump(input('get.id'));exit;
        $result = Db::name('friendship')->delete($id);
        if ($result > 0) {
            return $this->success('删除成功');
        } else {
            return $this->error('删除失败');
        }
    }

    public function update($id)
    {
        $date = Db::name('friendship')->find($id);
//        dump($date);exit;
        return view('admin@friendship/update',['date'=> $date]);

    }

    public function doupdate($id)
    {
//        dump(input('post.'));
        $data = [
            'name' => input('post.name'),
            'status' => input('post.status'),
            'url' => input('post.url'),
        ];

//        dump($data);exit;

        $result = Db::name('friendship')->where('id',$id)->update($data);

        if ($result) {
            return $this->success('编辑成功',url('admin/friendship/select'));
        } else {
            return $this->error('编辑失败');
        }


    }
}
